package com.rtx.edi.platform.log.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.edi.model.log.dto.PlApiRequestLogDto;
import com.rtx.edi.model.log.po.PlApiRequestLog;
import com.rtx.edi.model.response.EdiResponse;
import com.rtx.edi.platform.log.service.PlApiRequestContentLogService;
import com.rtx.edi.platform.log.service.PlApiRequestLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * api请求日志表  前端控制器
 * </p>
 *
 * @author wq
 * @since 2023-03-14
 */
@Api(tags = {"日志管理"})
@RestController
@RequestMapping("/v1/plApiRequestLog")
@CrossOrigin
public class PlApiRequestLogController {

    @Autowired
    private PlApiRequestLogService plApiRequestLogService;

    @Autowired
    private PlApiRequestContentLogService plApiRequestContentLogService;
    /**
     * 获取日志列表
     * @param plApiRequestLogDto
     * @return
     */
    @ApiOperation(value = "日志列表", notes = "分页获取日志列表")
    @PostMapping("selectPlApiRequestLogList")
    public EdiResponse selectPlApiRequestLogList(@RequestBody PlApiRequestLogDto plApiRequestLogDto){
        PlApiRequestLog plApiRequestLog = new PlApiRequestLog();
        BeanUtils.copyProperties(plApiRequestLogDto,plApiRequestLog);
        Page<PlApiRequestLog> pageParam = new Page<>(plApiRequestLogDto.getPageNum(), plApiRequestLogDto.getPageSize());
        plApiRequestLogService.selectPlDepartmentList(pageParam,plApiRequestLog);
        return  EdiResponse.success().data("page",pageParam);
    }

    /**
     * 根据日志流水号获取报文
     * @param plApiRequestLogDto
     * @return
     */
    @ApiOperation(value = "获取日志报文", notes = "根据日志流水号获取日志报文")
    @PostMapping("selectPlApiRequestContentLogByLogNo")
    public EdiResponse selectPlApiRequestContentLogByLogNo(@RequestBody PlApiRequestLogDto plApiRequestLogDto){
        return  EdiResponse.success().data("item",plApiRequestContentLogService.selectplApiRequestContentLogByLogNo(plApiRequestLogDto.getLogNo()));
    }
}
